import request from '@/utils/request'
import { CategoryResponseData, Attr } from './type'
enum API {
  C1_URL = '/admin/product/getCategory1',
  C2_URL = '/admin/product/getCategory2/',
  C3_URL = '/admin/product/getCategory3/',
  ATTR_URL = '/admin/product/attrInfoList/',
  ADD_OR_UPDATE_RUL = '/admin/product/saveAttrInfo',
  DELETE_URL = '/admin/product/deleteAttr/',
}

export const getC1Data = () => {
  return request.get<any, CategoryResponseData>(API.C1_URL)
}
export const getC2Data = (category1ID: number) => {
  return request.get<any, CategoryResponseData>(API.C2_URL + category1ID)
}
export const getC3Data = (category2Id: number) => {
  return request.get<any, CategoryResponseData>(API.C3_URL + category2Id)
}

export const getAttrData = (
  category1Id: any,
  category2Id: any,
  category3Id: any,
) => {
  return request.get<any, any>(
    API.ATTR_URL + `/${category1Id}/${category2Id}/${category3Id}`,
  )
}

export const addOrUpdateAttr = (data: Attr) => {
  return request.post<any, any>(API.ADD_OR_UPDATE_RUL, data)
}

export const deleteAttr = (id: any) => {
  return request.delete<any, any>(API.DELETE_URL + id)
}
